import React from "react";
class ClockG extends React.Component {
    constructor() {
        super()
        this.state = {
            timer: new Date().toLocaleTimeString()
        }
    }
    componentDidMount(){
        this.tick()
    }
    componentWillUnmount(){
        clearInterval(this.interval)
    }
    tick(){
       this.interval=setInterval(()=>{
        this.setState({
            timer:new Date().toLocaleTimeString()
        })
      },300)
    }
    render() {
        return (
            <fieldset>
                <legend>这是一个神奇的时钟</legend>
                <h1>北京时间：{this.state.timer}</h1>
            </fieldset>
        )
    }
}
export default ClockG